home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 126-150 / disk_128 / mrbackup / diskmisc.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  106 lines

  1. /* DiskMisc.c - miscellaneous disk support routines.
  2.  * Mark Rinfret (et al), 1987
  3.  */
  4.  
  5. /*#define DEBUG*/
  6.  
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <exec/ports.h>
  10. #include <exec/io.h>
  11. #include <libraries/dosextens.h>
  12. #include <functions.h>
  13.  
  14. extern LONG     sendpkt();
  15.  
  16. /* This routine returns the number of disk blocks remaining on the
  17.  * drive specified by 'name'.  Though 'name' would typically be the
  18.  * drive name or volume name, it can also be the name of any file
  19.  * on the disk drive.
  20.  * Called with:
  21.  *        name:        disk device or volume name
  22.  * Returns:
  23.  *        > 0 => number of blocks available
  24.  *        < 0 => error status
  25.  */
  26.  
  27. long DiskBlocks(name)
  28.     char *name;
  29. {
  30.     struct FileLock *lock = NULL;
  31.     struct InfoData *info = NULL;
  32.     long int blocks = -1L;
  33.     long IoErr();
  34.  
  35.     if (lock = (struct FileLock *) Lock(name,ACCESS_READ)) {
  36.         if (info = AllocMem((long)sizeof(struct InfoData),MEMF_PUBLIC)) {
  37.             if (Info(lock,info)) {
  38.                 blocks = info->id_NumBlocks - info->id_NumBlocksUsed;
  39.             }
  40.             else {
  41.                 blocks = -IoErr();
  42. #ifdef DEBUG
  43.                 printf("DiskBlocks: can't get Info on %s; error %ld\n",
  44.                     name, blocks);
  45. #endif
  46.                 }
  47.         }
  48.         else {
  49.             blocks = -ERROR_NO_FREE_STORE;
  50. #ifdef DEBUG
  51.             puts("DiskBlocks: no memory!");
  52. #endif
  53.         }
  54.     }
  55.     else {
  56.         blocks = -IoErr();
  57. #ifdef DEBUG
  58.         printf("DiskBlocks: can't lock %s; error %ld\n",name,blocks);
  59. #endif
  60.     }
  61.  
  62.     if (lock)    UnLock(lock);
  63.     if (info)    FreeMem(info,(long)sizeof(struct InfoData));
  64.     return blocks;                    /* bad status indicator */
  65. }
  66.  
  67. /* Disk ACTION_INHIBIT support routine.
  68.  * Author:        Mark R. Rinfret
  69.  * Date:        06/29/87
  70.  * 
  71.  * This routine provides support for user-written disk formatting, copy
  72.  * operations which benefit from suppressing/restoring disk validation.
  73.  */
  74.  
  75. int
  76. Inhibit(drivename, code)
  77.     char *drivename; int code;
  78. {
  79.     struct MsgPort     *task;
  80.     LONG     arg[2];
  81.     LONG     rc;
  82.  
  83.     if (!(task=(struct MsgPort *) DeviceProc(drivename))) 
  84.         return 1;                        /* fail, darn it! */
  85.  
  86.     arg[0] = code;
  87.  
  88.     /* Now, cross all your fingers and toes... */
  89.  
  90.     return ( !sendpkt(task,ACTION_INHIBIT,arg,1));
  91. }
  92.  
  93.  
  94. #ifdef DEBUG
  95. main()
  96. {
  97.     long blocks;
  98.  
  99.     blocks = DiskBlocks("df0:");
  100.     if (blocks == -1L)
  101.         puts("Bad status from DiskBlocks()");
  102.     else
  103.         printf("Disk blocks left on df0: %ld\n",blocks);
  104. }
  105. #endif
  106.